/*
 * Palabra.cpp
 *
 *  Created on: 13/09/2012
 *      Author: rcasal
 */

#include "Palabra.h"

namespace palabra {

Palabra::Palabra() {
	this->word = "";
}

Palabra::Palabra(string w) {
	this->word = w;
}

string Palabra::intToString(int entero){
	stringstream sstream;
	sstream << entero;
	return sstream.str();
}

int Palabra::stringToInt(string cadena){

	istringstream buffer(cadena);
	int value;
	buffer >> value;
	return value;
}

Palabra::~Palabra() {
}


string Palabra::remove_tildes(char let , string cadena, int pos){

	if(let>='A' && let<='Z') cadena[pos]=let+32;

	else if((let==-79 || let==-111)) cadena.replace(pos-1,2, "n" );
	//Eliminamos tildes a la a
	else if( (let==-95 || let==-127 || let==-124 || let==-92))
		cadena.replace(pos-1, 2, "a");
	//Eliminamos tildes a la e
	else if((let==-87 || let==-119 || let==-117 || let==-85))
		cadena.replace(pos-1, 2, "e");
	//Eliminamos tildes a la i
	else if((let==-83 || let==-115 || let==-113 || let==-81))
		cadena.replace(pos-1, 2, "i");
	//Eliminamos tildes a la o
	else if(  (let==-77 || let==-109 || let==-106 || let==-74))
		cadena.replace(pos-1, 2, "o");
	//Eliminamos tildes a la u
	else if( (let==-70 || let==-102 || let==-100 || let==-68))
		cadena.replace(pos-1, 2, "u");

	return cadena;
}

string Palabra::normalizar(){

	int longitud= word.length();

	for (int i=0; i < longitud; i++){
			if (word[i] != -61){
				word=remove_tildes(word[i],word,i);
			}
	}

	return word;
}

void Palabra::remove_character(char caract, string &cadena){
	while(cadena.find_first_of(caract) != string::npos){
		cadena.erase(cadena.find_first_of(caract), 1);
		}

}

void Palabra::remove_character_to_end(char caract, string &cadena){
	if(cadena.find_first_of(caract) != string::npos){
		cadena.erase(cadena.find_first_of(caract), cadena.length());
	}
}


} /* namespace palabra */
